<template>
	<div v-show="showPage">
		<div style="border-bottom: 1px solid #ddd;">
			<h3>数据源</h3>
		</div>
		<div style="margin-top: 10px;">
			主数据源
			<el-select size="mini" v-model="tableName" placeholder="请选择"  clearable filterable>
				<el-option v-for="item in modelList" :key="item.tableName" :label="item.name" :value="item.tableName">
				</el-option>
			</el-select>
		</div>
		<div style="margin-top: 10px;" v-show="showSubTableName">
			子数据源
			<el-select size="mini" v-model="subTableName" placeholder="请选择"  clearable filterable>
				<el-option v-for="item in modelList" :key="item.tableName" :label="item.name" :value="item.tableName">
				</el-option>
			</el-select>
		</div>
	</div>
</template>

<script>
	import restUtil from '@/utils/restUtil.js';
	export default {
		name: "DataSourceSelectPage",
		props: ["scope"],
		data() {
			return {
				showPage: false,
				showSubTableName:false,
				modelList: [],
				tableName:"",
				subTableName:"",
			}
		},
		methods: {
			init() {
				var that = this;
				restUtil.getAction(this,"webide/pagewizarddialog/initDataSourceSelectPage").then(
					function(response) {
						if (response.data.code == 1) {
							that.modelList = response.data.tableInfoList;
						} else {
							that.$alert(response.data.message, '提示')
						}
					});
			},
			setVisible(visible) {
				this.showPage = visible;
				if(visible){
					this.showSubTableName="formview"==this.scope.pageTypeSelectPage.pageType;
					if(this.modelList.length==0){
						this.init();
					}
				}
			},getReturnData(){
				var name="";
				var treeTable;
				for(var i=0;i<this.modelList.length;i++){
					if(this.modelList[i].tableName==this.tableName){
						name=this.modelList[i].name;
						treeTable=this.modelList[i].treeTable;
					}
				}
				var index=name.indexOf("(");
				name=name.substring(0,index);
				var data= {"tableName":this.tableName,"name":name,"treeTable":treeTable};
				if(this.showSubTableName){
					data["subTableName"]=this.subTableName;
				}
				return data;
			},getPreviousPage(){
				return "pageTypeSelectPage";
			},getNextPage(){
				return "pageBaseInfoPage";
			},isCompletedPage(){
				return false;
			}
		},
	}
</script>

<style>
</style>
